package br.com.duosoftware.orcamento.services;

import br.com.duosoftware.orcamento.hibernate.HibernateUtil;
import br.com.duosoftware.orcamento.utils.ReportUtil;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Locale;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperRunManager;

/**
 *
 * @author daniel
 *
 */
public class RelatorioService {


    public void imprimirRelatorio(String diretorio, String relatorio)
            throws ParseException, JRException, IOException, SQLException {

        ReportUtil reportUtil = new ReportUtil();

        HashMap parametros = new HashMap();

        parametros.put("REPORT_LOCALE", new Locale("pt", "BR"));

        parametros.put("SUBREPORT_DIR", reportUtil.getJavaPath() + "/" + diretorio + "/");

        Connection connection = HibernateUtil.getInstance().getSession().connection();

        byte[] pdfRelatorio = JasperRunManager.runReportToPdf(reportUtil.getJavaPath() + "/" + diretorio + "/" + relatorio + ".jasper", parametros, connection);

        reportUtil.mostrarRelatorio(pdfRelatorio, reportUtil.getResponse(), relatorio);

    }

}
